<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-projectProtocolTemplate-add">
        	<div class="form-group">	
				<label class="col-sm-3 control-label">项目名称：</label>
				<div class="col-sm-8">
					<select id="projectId" name="projectId" class="form-control m-b" th:with="type=${projects}" onchange="resetValidate()">
	                    <option th:each="projects : ${type}" th:text="${projects.projectName}" th:value="${projects.projectId}" th:selected="${projects.projectId == defaultProjectId}"></option>
	                </select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">模板名称：</label>
				<div class="col-sm-8">
					<input id="templateName" name="templateName" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">消息头域：</label>
				<div class="col-sm-8">
					<textarea id="headMsg" name="headMsg" class="form-control placeholder" placeholder="示例:Authorization=Base64(admin:123456);Content-Type=application/json    多个头域以;分隔"></textarea>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">证书路径：</label>
				<div class="col-sm-8">
					<textarea id="cerificatePath" name="cerificatePath" class="form-control placeholder" placeholder="客户端中的证书路径，非必填项，HTTPS双向认证才会用到，HTTPS单向认证此项请保持为空，格式：【https证书路径;密钥】"></textarea>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">编码格式：</label>
				<div class="col-sm-8">
					<div class="radio-box">
					  <input type="radio" id="encoding" name="encoding" value="UTF-8" checked>
					  <label>UTF-8编码</label>
				    </div>
				    <div class="radio-box">
				      <input type="radio" id="encoding" name="encoding" value="GBK">
					  <label>GBK编码</label>
				    </div>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">响应超时(秒)：</label>
				<div class="col-sm-8">
					<input id="timeout" name="timeout" class="form-control" type="text" value="60">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">头域返回：</label>
				<div class="col-sm-8">
					<div class="radio-box">
					  <input type="radio" id="isResponseHead" name="isResponseHead" value="0" checked>
					  <label>响应不返回</label>
				    </div>
				    <div class="radio-box">
					  <input type="radio" id="isResponseHead" name="isResponseHead" value="1">
					  <label>响应返回</label>
				    </div>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">状态码返回：</label>
				<div class="col-sm-8">
					<div class="radio-box">
					  <input type="radio" id="isResponseCode" name="isResponseCode" value="0" checked>
					  <label>响应不返回</label>
				    </div>
				    <div class="radio-box">
					  <input type="radio" id="isResponseCode" name="isResponseCode" value="1">
					  <label>响应返回</label>
				    </div>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<textarea id="remark" name="remark" class="form-control"></textarea>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "testmanagmt/projectProtocolTemplate";
		
		$.validator.setDefaults({
			ignore:":hidden:not(select)",
			submitHandler : function() {
				save();
			}
		});
		
		$("#form-projectProtocolTemplate-add").validate({
			rules:{
				projectId:{
					required:true,
				},
				templateName:{
					required:true,
					minlength: 1,
        			maxlength: 50,
                    remote: {
                        url: prefix + "/checkProjectProtocolTemplateNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            name: function () {
                                return $.common.trim($("#templateName").val());
                            },
                            projectId: function () {
                                return $.common.trim($("#projectId").val());
                            }		
                        },
                        dataFilter: function (data, type) {
                        	return $.validate.unique(data);
                        }
                    }
				},
				timeout:{
					required:true,
					min: 1,
        			max: 300
				}
			},
        	messages: {
                "templateName": {
                    remote: "协议模板名称已经存在"
                }
            }
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/add", $('#form-projectProtocolTemplate-add').serialize());
	        }
	    }
		
		/*更换项目名后，清空模板名称重新检验*/
		function resetValidate() {
			$.validate.resetForm();
			$("#templateName").val("");
		}
	</script>
</body>
</html>
